//
//  navViewStyle.m
//  ZITHER
//
//  Created by weixin on 2018/11/15.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "navViewStyle.h"
#define centerYH (CGFloat)(Is_Iphone_X_Series?(20):(10))

@implementation navViewStyle

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, NaviHeight-1, kScreenW, 1)];
//        view.backgroundColor = [UIColor colorWithHex:<#(NSString *)#>];
        [view setShadowType1WithColor:[UIColor defaultShadowColor] offset:CGSizeMake(0, 5) opacity:1 radius:3];
        [self addSubview:view];

        [self setUI];
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
            self.backgroundColor =  Main_Token_Model_MANAGER.backgroundColor ;
        }
    }
    return self;
}


-(void)setUI{
    [self addSubview:self.leftBtn];
    [self addSubview:self.rightBtn];
    [self addSubview:self.title];
    [self addSubview:self.bottomLine];
}

-(BaseBtn *)leftBtn
{
    if (!_leftBtn) {
        _leftBtn = [[BaseBtn alloc]initializeFrame:CGRectMake(15, 0, 20, 20) NormalImage:@"common_back" SeleImage:@"common_back"];
//        [self.leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 20, 0)];//调整图片大小5:2
        _leftBtn.centerY = self.centerY+centerYH;
        @weakify(self);
        [[_leftBtn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            [self.getNav popViewControllerAnimated:YES];
        }];
        _leftBtn.backgroundColor = [UIColor clearColor];
        [_leftBtn setLocalImage:@"common_back"];

//        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
//            [_leftBtn setImage:[UIImage imageNamed:Normalimage] forState:UIControlStateNormal];
//            [_leftBtn setImage:[UIImage imageNamed:Seleimage] forState:UIControlStateSelected];
//        }
    }
    return _leftBtn;
}

-(BaseBtn *)rightBtn
{
    if (!_rightBtn) {
        _rightBtn = [BaseBtn initCustomBtn:@[@"common_back"]];
        _rightBtn.frame = CGRectMake(kScreenW-20, 0, 20, 20);
//        _rightBtn = [[BaseBtn alloc]initializeFrame:CGRectMake(kScreenW-20, 0, 20, 20) NormalImage:@"common_back" SeleImage:@"common_back"];
        _rightBtn.centerY = self.centerY+centerYH;
        _rightBtn.hidden = YES;
        _rightBtn.backgroundColor = [UIColor clearColor];
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
            [_rightBtn setTitleColor: Main_Token_Model_MANAGER.navTitleColor forState:UIControlStateNormal];
        }else{
            [_rightBtn setTitleColor:[UIColor colorWithHex:@"333333"] forState:UIControlStateSelected];
        }
        }
    return _rightBtn;
}

-(BaseLab *)title
{
    if (!_title) {
        _title = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 200,20) text:@"" font:17 textColor:[UIColor colorWithHex:@"333333"] isBold:NO numberOfLines:1];
        _title.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:17];

        _title.center = self.center;
        _title.centerY = self.centerY+centerYH;
        _title.textAlignment = NSTextAlignmentCenter;
        _title.backgroundColor = [UIColor clearColor];
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
            _title.textColor = Main_Token_Model_MANAGER.navTitleColor ;
        }else{
            _title.textColor = [UIColor colorWithHex:@"333333"] ;
        }
    }
    return _title;
}

-(BaseView *)bottomLine
{
    if (!_bottomLine) {
        _bottomLine = [[BaseView alloc]initWithFrame:CGRectMake(0, self.frame.size.height-1, kScreenW,1)];
        [_bottomLine setShadowType1WithColor:[UIColor defaultShadowColor] offset:CGSizeMake(0, 5) opacity:1 radius:3];
    }
    return _bottomLine;
}

#pragma mark - Setter
- (void)setIsShowShadow:(BOOL)isShowShadow {
    _isShowShadow = isShowShadow;
    if (_isShowShadow) {
        [self.bottomLine setShadowType1WithColor:[UIColor defaultShadowColor] offset:CGSizeMake(0, 3) opacity:1 radius:2];
        self.bottomLine.hidden = NO;
    } else {
        [self.bottomLine setShadowType1WithColor:[UIColor clearColor] offset:CGSizeMake(0, 5) opacity:1 radius:3];
        self.bottomLine.hidden = YES;
    }
}

@end
